import $ from 'jQuery';
(function () {
  let $vue = null;
  $vue = new Vue({
    el: '.update-account-management-hook',
    data: {
      account: {
        'email': '',
        'gender': 1,
        'mobile': '',
        'userName': ''
      }
    },
    methods: {
      goBack: function () {
        M.Page.emitPrePage();
      }
    },
    mounted: function () {
      this.$nextTick(() => {
        $('.detail-form-hook').validate({
          debug: true,
          rules: {
            mobile: {
              required: true,
              phoneCN: true,
              minlength: 11,
              maxlength: 11
            },
            email: {
              email: true,
              required: true,
              minlength: 1,
              maxlength: 50
            },
            userName: {
              required: true,
              minlength: 1,
              maxlength: 10
            },
            password: {
              required: true,
              minlength: 8,
              checkPwd: true,
              maxlength: 20
            },
            confirmPassword: {
              required: true,
              equalTo: '#equalToPassowrd',
            }
          },
          submitHandler: function (form) {
            if($.trim($vue.$data.account.userName) == ""){
              layer.alert('用户姓名不能为空');
              return false;
            }
            IOT.showOverlay('保存中，请稍等...');
            let params = $vue.$data.account;
            IOT.getServerData(URI.SYSTEM.ACCOUNT_MANAGEMENT.UPDATE.SAVE, params, function (ret) {
              IOT.hideOverlay();
              if (ret && ret.code === 200) {
                IOT.tips('保存成功！', 'success');
                M.Table.refresh.all();
                M.Page.emitPrePage();
              } else {
                IOT.tips(ret.msg || '操作失败，请重试！', 'error', 1000, null);
              }
            });
            return false;
          }
        });
      });
    }
  });
})();